<?php
declare (strict_types = 1);

namespace app\common\service;

use think\facade\Request;
use app\common\model\AdminZbuserinfo as M;
use app\common\model\AdminZavote as MA;
use app\common\model\AdminZegzhpz as ME;
use app\common\validate\AdminZbuserinfo as V;
use think\facade\Db;
use think\facade\Cache;

class AdminZbuserinfo
{
    // 删除
    public static function goRemove($id)
    {
        $model = M::find($id);
        if ($model->isEmpty()) return ['msg'=>'数据不存在','code'=>201];
        try{
            $whe['biaoid']=$model['biaoid'];
            $whe['utoken']=$model['uid'];
            Db::name("admin_zitjxx")->where($whe)->delete();
            $model->delete();
        }catch (\Exception $e){
            return ['msg'=>'操作失败'.$e->getMessage(),'code'=>201];
        }
    }

    // 首页图表数据
    public static function goTubiaoshuju($biaoid)
    {
        $timetoday = date("Y-m-d");   //今日
        $time2today = date("Y-m-d",strtotime("+1 day"));  //  明日
        $yi = M::where('biaoid', $biaoid)->where('datetime', 'between', [$timetoday, $time2today])->count();

        $time3today = date("Y-m-d",strtotime("-1 day"));  //  昨日
        $er = M::where('biaoid', $biaoid)->where('datetime', 'between', [$time3today, $timetoday])->count();

        $time4today = date("Y-m-d",strtotime("-6 day"));  //  七日前
        $san = M::where('biaoid', $biaoid)->where('datetime', 'between', [$time4today, $time2today])->count();
        
        $si = M::where('biaoid', $biaoid)->count();

        return ['msg'=>'操作成功','code'=>200,'data'=>['yi' =>$yi, 'er' => $er, 'san' => $san, 'si' => $si]];
    }  

    // 其他项
    public static function goQitaxiang($biaoid)
    {
        $res = MA::where('id', $biaoid)->find();
        if($res['shuxing'] == 1){
            $shuxing = explode(',',$res['shuxingzhi']);
            $shuxing = array_filter($shuxing);
            $shuxingxq = array();
            foreach ($shuxing as $k => $v) {
                $shuxingzhi = ME::find($v);
                $shuxingxq[$k]['field'] = $shuxingzhi['appsecret'];
                $shuxingxq[$k]['title'] = urlencode($shuxingzhi['wxgzgname']);
                $shuxingxq[$k]['unresize'] = "true";
                $shuxingxq[$k]['align'] = "center";
            }
            $qitaxiang = "";
            for($i=0;$i < count($shuxingxq);$i++){
                $qitaxiang .= urldecode(json_encode($shuxingxq[$i],JSON_FORCE_OBJECT)).',';
            }
            $qitaxiang = str_ireplace('"', "'", $qitaxiang);
            //$qitaxiang = "{field: 'datetime',title: '参加时间',unresize: 'true',align: 'center'},{field: 'datetime',title: '参加时间',unresize: 'true',align: 'center'},";
        } else {
            $qitaxiang = "";
        }
        
        return ['msg'=>'操作成功','code'=>200,'data'=>['qitaxiang' =>$qitaxiang]];
    }  
    
}
